//
//  webViewController.m
//  jingjing2.0
//
//  Created by apple on 16/5/4.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "WebViewController.h"
@interface WebViewController ()<UIWebViewDelegate>
@property(nonatomic,strong)UIWebView *web;
@end

@implementation WebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    if ([self.pageUrl rangeOfString:@"#"].location!= NSNotFound) {
        NSRange range=[self.pageUrl rangeOfString:@"#"];
       self.pageUrl = [[self.pageUrl stringByReplacingCharactersInRange:range withString:@"%23"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    }
    [self setUpWebView];
    [self setUpButton];
}

-(void)setUpWebView
{
    _web=[[UIWebView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
    _web.backgroundColor=[UIColor whiteColor];
    NSURL *nsurl=[NSURL URLWithString:self.pageUrl];
    NSURLRequest *request=[[NSURLRequest alloc] initWithURL:nsurl];
    _web.scalesPageToFit=YES;
    _web.delegate=self;
    [_web loadRequest:request];
    [self.view addSubview:_web];
    
    [MBProgressHUD showHUDAddedTo:_web animated:YES];
}
-(void)setUpButton
{
    CGSize size=_web.frame.size;
    UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(0,size.height-80,size.width, size.height)];
    btn.backgroundColor=[UIColor clearColor];
    [btn addTarget:self action:@selector(goToMoneyViewController) forControlEvents:UIControlEventTouchUpInside];
   [self.view addSubview:btn];
    [self.view bringSubviewToFront:btn];
}
-(void)goToMoneyViewController
{
    SaveMoneyViewController *money=[[SaveMoneyViewController alloc]init];
    money.title=@"充值";
    money.hidesBottomBarWhenPushed=YES;
    [self.navigationController pushViewController:money animated:YES];
    
}
-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [GeneralTool hideTabBar];
    
}
-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [GeneralTool showTabBar];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [MBProgressHUD hideHUDForView:_web];
    //清除内存
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
    [[NSUserDefaults standardUserDefaults]synchronize];
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [MBProgressHUD hideHUDForView:_web];
    //清除内存
    [[NSUserDefaults standardUserDefaults] setInteger:0 forKey:@"WebKitCacheModelPreferenceKey"];
    [[NSUserDefaults standardUserDefaults]synchronize];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
   }




@end
